#pragma once 

#include <cstdint>
#include <vector>
#include <queue>
#include <atomic>
#include <mutex>
#include <memory>

#include "Schedule.h"

class CThread;
class CTaskBase;

class WHENGINE_API CThreadPoolSchedule  : public ISchedule
{
public:
    CThreadPoolSchedule(uint64_t InWorkerNum);
    ~ CThreadPoolSchedule();

    //Scheduale interface begin********
    virtual void AddTask(TThreadSafeSharedPtr<CTaskBase> InTask) override ;

    //Schedual interface end************

    bool HaveWaitingTask();

    void Shutdown();
protected:

    std::vector<CThread*> Threads;

    //run in thread
    void FindAndRunWork(uint64_t ThreadIndex);

    std::mutex WaitingTasksLocker;
    std::queue<TThreadSafeSharedPtr<CTaskBase>> WaitingTasks;

    std::atomic<uint32_t> WorkingThreadNum;

};